/*
 * @Author: szx
 * @Date: 2022-06-06 11:38:10
 * @LastEditTime: 2022-06-06 11:42:47
 * @Description:
 * @FilePath: \leetcode\面试题\16\06\06.js
 */
/**
 * @param {number[]} a
 * @param {number[]} b
 * @return {number}
 */
var smallestDifference = function (a, b) {
    a.sort((a, b) => a - b);
    b.sort((a, b) => a - b);
    let i = 0,
        j = 0;
    let res = Infinity;
    while (i < a.length && j < b.length) {
        res = Math.min(res, Math.abs(a[i] - b[j]));
        if (a[i] < b[j]) i++;
        else j++;
    }
    return res;
};
